﻿
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
	#region FactoryOrder Model -(by fangyifeng at 2013/12/23 18:42:00)

	/// <summary>
	/// FactoryOrder object'FactoryOrder'.
	/// </summary>
    [Serializable]
	public class FactoryOrder : System.IComparable
		{
		#region Member Variables
		
		protected Guid _id;
		protected string _orderID;
		protected DateTime _orderDate;
        protected decimal _amount;
        protected decimal _orderrealamount;
		protected decimal _payAmount;
		protected decimal _balance;
		protected bool _isCheckAmount;
		protected bool _isPaid;
		protected string _remark;
		protected string _payNumber;
		protected short _orderStatus;
        protected bool _IsMyOrder;
        protected bool _IsStockIn;
		protected Factory _factory;
		
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public FactoryOrder() { }

		public FactoryOrder( string orderID, DateTime orderDate, decimal amount, decimal payAmount, decimal balance, bool isCheckAmount, bool isPaid, string remark, string payNumber, short orderStatus, Factory factory )
		{
			this._orderID = orderID;
			this._orderDate = orderDate;
			this._amount = amount;
			this._payAmount = payAmount;
			this._balance = balance;
			this._isCheckAmount = isCheckAmount;
			this._isPaid = isPaid;
			this._remark = remark;
			this._payNumber = payNumber;
			this._orderStatus = orderStatus;
			this._factory = factory;
		}

		#endregion

		#region Public Properties

		public virtual Guid Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public virtual string OrderID
		{
			get { return _orderID; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for OrderID", value, value.ToString());
				_orderID = value;
			}
		}

		public virtual DateTime OrderDate
		{
			get { return _orderDate; }
			set { _orderDate = value; }
		}

		public virtual decimal Amount
		{
			get { return _amount; }
			set { _amount = value; }
		}

        public virtual decimal OrderRealAmount
		{
            get { return _orderrealamount; }
            set { _orderrealamount = value; }
		}
        
		public virtual decimal PayAmount
		{
			get { return _payAmount; }
			set { _payAmount = value; }
		}

		public virtual decimal Balance
		{
			get { return _balance; }
			set { _balance = value; }
		}

		public virtual bool IsCheckAmount
		{
			get { return _isCheckAmount; }
			set { _isCheckAmount = value; }
		}

		public virtual bool IsPaid
		{
			get { return _isPaid; }
			set { _isPaid = value; }
		}

		public virtual string Remark
		{
			get { return _remark; }
			set
			{
				if ( value != null && value.Length > 250)
					throw new ArgumentOutOfRangeException("Invalid value for Remark", value, value.ToString());
				_remark = value;
			}
		}

		public virtual string PayNumber
		{
			get { return _payNumber; }
			set
			{
				if ( value != null && value.Length > 500)
					throw new ArgumentOutOfRangeException("Invalid value for PayNumber", value, value.ToString());
				_payNumber = value;
			}
		}

		public virtual short OrderStatus
		{
			get { return _orderStatus; }
			set { _orderStatus = value; }
		}

        public virtual bool IsStockIn
        {
            get { return _IsStockIn; }
            set { _IsStockIn = value; }
        }
        public virtual bool IsMyOrder
        {
            get { return _IsMyOrder; }
            set { _IsMyOrder = value; }
        }
		public virtual Factory Factory
		{
			get { return _factory; }
			set { _factory = value; }
		}

		
        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
			if (!(obj is FactoryOrder))
				throw new InvalidCastException("This object is not of type FactoryOrder");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((FactoryOrder)obj).Id);
					break;
				case "OrderID":
					relativeValue = this.OrderID.CompareTo(((FactoryOrder)obj).OrderID);
					break;
				case "OrderDate":
					relativeValue = this.OrderDate.CompareTo(((FactoryOrder)obj).OrderDate);
					break;
				case "Amount":
					relativeValue = this.Amount.CompareTo(((FactoryOrder)obj).Amount);
					break;
				case "PayAmount":
					relativeValue = this.PayAmount.CompareTo(((FactoryOrder)obj).PayAmount);
					break;
				case "Balance":
					relativeValue = this.Balance.CompareTo(((FactoryOrder)obj).Balance);
					break;
				case "IsCheckAmount":
					relativeValue = (this.IsCheckAmount != null) ? this.IsCheckAmount.CompareTo(((FactoryOrder)obj).IsCheckAmount) : -1;
					break;
				case "IsPaid":
					relativeValue = (this.IsPaid != null) ? this.IsPaid.CompareTo(((FactoryOrder)obj).IsPaid) : -1;
					break;
				case "Remark":
					relativeValue = (this.Remark != null) ? this.Remark.CompareTo(((FactoryOrder)obj).Remark) : -1;
					break;
				case "PayNumber":
					relativeValue = (this.PayNumber != null) ? this.PayNumber.CompareTo(((FactoryOrder)obj).PayNumber) : -1;
					break;
				case "OrderStatus":
					relativeValue = this.OrderStatus.CompareTo(((FactoryOrder)obj).OrderStatus);
					break;
                default:
                    goto case "Id";
			}
            if (FactoryOrder.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
